package org.jtb.quickr;

import java.io.InputStream;
import java.util.Map;
import java.util.Set;

import org.jtb.quickr.PhotosSearchCriteria.Extra;

class PeopleGetPublicPhotosRequest extends MethodRequest {
    private String nsid;
    private String staticUrl;
    private Set<Extra> extras;
    
    protected PeopleGetPublicPhotosRequest(String baseUrl, String apiKey, String nsid, String staticUrl) throws QuickrException {
        super(baseUrl, apiKey, "flickr.people.getPublicPhotos");
        this.nsid = nsid;
        this.staticUrl = staticUrl;
    }
    
    public Set<Extra> getExtras() {
        return extras;
    }

    public void setExtras(Set<Extra> extras) {
        this.extras = extras;
    }
 
    protected Map<String,String> getArgs() {
        putArg("user_id", nsid);
        if (extras!=null & extras.size() > 0) {
            putArg("extras", join(extras, ','));
        }
        
        return super.getArgs();
    }
    
    public PhotosResponse execute() throws QuickrException {
        FlickrUrl furl = new ServiceMethodUrl(getBaseUrl(), getArgs(), getApiKey(), getMethod());
        
        Get get = new Get(furl.getUrl());
        InputStream is = get.execute();

        PhotosResponse pres = new PhotosResponse(is, staticUrl);
        
        return pres;
    }
}
